# -*-coding:utf-8-*-

from tornado.ioloop import IOLoop
from tornado import gen
import motor

# Adapts a callback-based asynchronous function for use in coroutines
# gen.Task()

db = motor.motor_tornado.MotorClient().test_database


@gen.coroutine
def do_insert_internel(i):
    future = db.test_collection.insert_one({'i': i})
    result = yield future
    print result
    raise gen.Return('zjx')


@gen.coroutine
def do_insert():
    for i in range(20):
        r = yield do_insert_internel(i)
        print r


IOLoop.current().run_sync(do_insert)

#
# @gen.coroutine
# def do_find_one():
#     document = yield db.test_collection.find_one({'i': {'$lt': 1}})
#     print document
#
#
# IOLoop.current().run_sync(do_find_one)
